package com.horizon.mobile.manage;

import android.content.Context;
import android.content.SharedPreferences;
/**
 * xml形式的文件存储
 * @author 左大明
 *
 */
public class SharePreferences {
	private static final String PREFERENCE_NAME = "HzoaFactory"; //文件名
	private static SharedPreferences sharedPreferences;
	private static SharePreferences mySharePreferences;
	private SharePreferences(Context context){
		if(sharedPreferences == null) {
			sharedPreferences = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE); 
		}
	}
	
	public static SharePreferences getInstance(Context context) {
		if(null == mySharePreferences) {
			mySharePreferences = new SharePreferences(context);
		}
		return mySharePreferences;
	}
	
	public void putUserName(String userName) {
		sharedPreferences.edit().putString("userName", userName).commit();
	}
	
	public String getUserName() {
		return sharedPreferences.getString("userName", "");
	}
	
	public void putLoginName(String loginName) {
		sharedPreferences.edit().putString("loginName", loginName).commit();
	}
	
	public String getLoginName() {
		return sharedPreferences.getString("loginName", "");
	}
	
	public void putDeptName(String deptName) {
		sharedPreferences.edit().putString("deptName", deptName).commit();
	}
	
	public String getDeptName() {
		return sharedPreferences.getString("deptName", "");
	}
	
	public void putRealName(String realName) {
		sharedPreferences.edit().putString("realName", realName).commit();
	}
	
	public String getRealName() {
		return sharedPreferences.getString("realName", "");
	}
	
	public void putPassword(String password) {
		sharedPreferences.edit().putString("password", password).commit();
	}
	
	public String getPassword() {
		return sharedPreferences.getString("password", "");
	}
	
	public void putIsLogin(boolean isLogin) {
		 sharedPreferences.edit().putBoolean("isLogin", isLogin).commit();
	}
	
	public boolean isLogin() {
		return sharedPreferences.getBoolean("isLogin", false);
	}
	
	public void putIsSavePassword(boolean isSavePassword) {
		 sharedPreferences.edit().putBoolean("isSavePassword", isSavePassword).commit();
	}
	
	public boolean getisSavePassword() {
		return sharedPreferences.getBoolean("isSavePassword", false);
	}
	
	public void putToken(String token) {
		sharedPreferences.edit().putString("token", token).commit();
	}
	
	public String getToken() {
		return sharedPreferences.getString("token", "");
	}
	

	public void putTenantCode(String tenantCode) {
		sharedPreferences.edit().putString("tenantCode", tenantCode).commit();
	}
	
	public String getTenantCode() {
		return sharedPreferences.getString("tenantCode", "");
	}
	
	public boolean isFirstOpen() {
		return sharedPreferences.getBoolean("firstOpen", true);
	}
	
	public void putIsFirstOpen(boolean isFirstOpen) {
		sharedPreferences.edit().putBoolean("firstOpen", isFirstOpen).commit();
	}

	public boolean getIsNeiwang() {
		return sharedPreferences.getBoolean("isNeiwang", true);
	}

	public void putIsNeiwang(boolean isNeiwang) {
		sharedPreferences.edit().putBoolean("isNeiwang", isNeiwang).commit();
	}
	
	public void putServerUrl(String serverUrl) {
		sharedPreferences.edit().putString("serverUrl", serverUrl).commit();
	}
	
	public String getServerUrlWW(String url) {
		return sharedPreferences.getString("serverUrlWW", url);
	}
	public void putServerUrlWW(String serverUrl) {
		sharedPreferences.edit().putString("serverUrlWW", serverUrl).commit();
	}

	public String getServerUrl(String url) {
		return sharedPreferences.getString("serverUrl", url);
	}
	public void putSuffix(String suffix) {
		sharedPreferences.edit().putString("suffix", suffix).commit();
	}

	public String getSuffix(String suffix) {
		return sharedPreferences.getString("suffix", suffix);
	}


	public void loginOut(){
		sharedPreferences.edit().putString("password", "").commit();
		sharedPreferences.edit().putString("userName", "").commit();
		sharedPreferences.edit().putString("realName", "").commit();
		sharedPreferences.edit().putBoolean("isLogin", false).commit();
		sharedPreferences.edit().putBoolean("isSavePassword", false).commit();
		sharedPreferences.edit().putString("userId", "").commit();
		sharedPreferences.edit().putString("token", "").commit();
		sharedPreferences.edit().putString("deptId", "").commit();
		sharedPreferences.edit().putString("deptName", "").commit();
	}
}
